const http = require("http");
const https = require("https")
const path = require("path")
const fs = require("fs")

http.createServer((req,res)=>{
    var str='';
    req.on("data",(chunk)=>{
        str+=chunk
    })
    req.on("end",()=>{
        var obj = JSON.parse(str)
        var filePath = path.join(__dirname,"/data.json")
        fs.readFile(filePath,(err,data)=>{
            if(err){
                console.log(err)
            }else{
                var flag = "true"
                data_1 = JSON.parse(data.toString('utf-8'))
                for(var i=0;i<data_1.userList.length;i++){
                    if(obj.userName==data_1.userList[i].userName&&obj.pwd==data_1.userList[i].pwd){
                        console.log("登陆成功")
                        console.log(obj.userName,obj.pwd)
                        flag = "false"
                        return
                    }else if(obj.userName==data_1.userList[i].userName || obj.pwd==data_1.userList[i].pwd || flag == "false"){
                        console.log("用户名、密码不正确")
                        return;
                    }
                }
            }
        })
    })
}).listen(8080)